<?php
//this model is using for users....
class Poi_model extends Model{
	
	function Poi_model()
	{
		parent::Model();
		$this->load->database();
	}
	
  public function details_poi() 
  {
    $this->CI =& get_instance();
  
    $this->db->select('* from tbl_poidetails');
    $this->CI->flexigrid->build_query();
    
    //Get contents
    $return['records'] = $this->db->get();
    
    //Build count query
    $this->db->select('count(poi_id) as record_count from tbl_poidetails');
    $this->CI->flexigrid->build_query(FALSE);
    $record_count = $this->db->get();
    $row = $record_count->row();
    
    //Get Record Count
    $return['record_count'] = $row->record_count;
  
    //Return all
    return $return;
  }
  
	function poi_count()
	{
		$result = $this->db->query("select * from tbl_poidetails");
		return $result->num_rows();
	}	
	
	function list_poi($num,$limitnum)
	{
		$result = $this->db->query("select * from tbl_poidetails order by poi_desc ASC limit ".$num." , ".$limitnum);
		return $result;
	}
	
	function insert_poi()
	{
		
		$check = $this->db->query("select * from tbl_poidetails where poi_desc like '".$_POST['poi_name']."'");
		
		if($check->num_rows() == 0)
		{
			$this->db->set('poi_desc', $_POST['poi_name']);
			$this->db->insert('tbl_poidetails');	
		}
		else
		{
			redirect("poi/duplicate_poi");
		}
	}
	
	function poi_edit($id)
	{
		$result = $this->db->query("select * from tbl_poidetails where poi_id =".$id);
		return $result;
	}
	
	function edit_save()
	{
		$data = array(
               'poi_desc' => $_POST['poi_name'],
		            );

	$this->db->where('poi_id', $_POST['id']);
	$this->db->update('tbl_poidetails', $data);
	}
	
}
